from typing import *


class Solution:
    def modifiedMatrix(self, matrix: List[List[int]]) -> List[List[int]]:
        mx = [-2 for _ in range(len(matrix[0]))]
        ls = []
        for i in range(len(matrix)):
            for j in range(len(matrix[i])):
                mx[j] = max(mx[j], matrix[i][j])
                if matrix[i][j] == -1:
                    ls.append((i, j))
        for i, j in ls:
            matrix[i][j] = mx[j]
        return matrix
